package com.example.testcontent;

import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Intent;
import android.database.ContentObserver;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    ContentResolver _resolver;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        _resolver = getContentResolver();
        _resolver.registerContentObserver(Uri.parse("content://com.example.testcontent/test"), true, new ContentObserver(null) {
            @Override
            public void onChange(boolean selfChange) {
                super.onChange(selfChange);

                Log.d("main", "changed");
            }
        });
    }

    public void onModifyClick(View view) {
        ContentValues vals = new ContentValues();
        vals.put("main", "update test");
        _resolver.update(Uri.parse("content://com.example.testcontent/test"), vals, null, null);
    }

    public void onDeleteClick(View view) {
        _resolver.delete(Uri.parse("content://com.example.testcontent/test"), null, null);
    }

    public void onInsertClick(View view) {
        ContentValues vals = new ContentValues();
        vals.put("main", "insert test");
        _resolver.insert(Uri.parse("content://com.example.testcontent/test"), vals);
    }

    public void onQueryClick(View view) {
        _resolver.query(Uri.parse("content://com.example.testcontent/test"), null, null, null, null);
    }
}